<template>
  <div class="icons-container">
    <div v-for="item of iconsMap" :key="item">
      <el-tooltip placement="top">
        <div slot="content">
          {{ generateIconCode(item) }}
        </div>
        <div class="icon-item">
          <XsvgIcon :name="item" class-name="disabled" />
          <span>{{ item }}</span>
        </div>
      </el-tooltip>
    </div>
  </div>
</template>

<script>
const req = require.context('@/assets/svg', false, /\.svg$/);
const requireAll = requireContext => requireContext.keys();

const re = /\.\/(.*)\.svg/;

const icons = requireAll(req).map(i => {
  return i.match(re)[1];
});

export default {
  name: 'Icons',
  data () {
    return {
      iconsMap: icons
    };
  },
  methods: {
    generateIconCode (symbol) {
      return `<XsvgIcon name="${symbol}" />`;
    }
  }
};
</script>

<style lang="scss" scoped>
.icons-container {
  overflow: hidden;
  .icon-item {
    margin: 20px;
    height: 110px;
    text-align: center;
    width: 110px;
    float: left;
    color: #fff;
    cursor: pointer;
  }
  .svg-icon {
    color: rgba(255, 255, 255, 0.8);
    width: 0.4rem;
    height: 0.4rem;
  }
  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }
  .disabled{
    pointer-events: none;
  }
}
</style>
